/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 battlefield_terrain_map.cpp

	$Header: /resource_editor/battlefield_passablity_map.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "battlefield_passablity_map.h"
#include "streambuf_operators.h"

namespace 
{
	int k_version = 1;
};

////////////////////////////////////////////////////////////////////////////////////////
// battlefield passablity map 
////////////////////////////////////////////////////////////////////////////////////////

t_battlefield_passablity_map::t_battlefield_passablity_map()
{}

t_battlefield_passablity_map::t_battlefield_passablity_map(
		int										map_size,
		int										tile_height,
		t_screen_point const &					view_size,
		t_int8	const &		value ) : t_isometric_map<t_int8>(map_size,tile_height,view_size,value )
{}

t_battlefield_passablity_map::~t_battlefield_passablity_map()
{}	

void	t_battlefield_passablity_map::read( std::streambuf& buffer, int version_header )
{
	//this class has a templated get<> so have to use :: notation to use global scope get functions

	int version			= ::get<int>(buffer);
	int size			= ::get<int>(buffer);
	int tile_height		= ::get<int>(buffer);

	t_screen_point		view_size;

	buffer >> view_size;

	initialize( size, tile_height, view_size );

	t_map_point_2d					point;
	int								row_end;
	
	point.row = get_size();
	
	while (point.row--)
	{
		point.column	= get_row_start( point.row );
		row_end			= get_row_end( point.row );
		
		::read( buffer, &get(point), row_end - point.column );
	}
}

void	t_battlefield_passablity_map::write( std::streambuf& buffer, t_progress_handler* handler )
{
	//header information

	put<int>(buffer, k_version);
	put<int>(buffer, m_size);
	put<int>(buffer, m_tile_height);
	buffer << m_view_size;

	//the data itself.

	t_map_point_2d					point;
	int								row_end;
	
	point.row = get_size();
	
	while (point.row--)
	{
		point.column	= get_row_start( point.row );
		row_end			= get_row_end( point.row );
		
		::write( buffer, &get(point), row_end - point.column );
	}
}

